package com.qianfeng.interceptor;

import com.qianfeng.entity.User;
import com.sun.org.apache.xpath.internal.operations.String;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author: 85907
 * @date: 2020/7/27 9:35
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        User user = (User) request.getSession().getAttribute("USER");
        if( user == null ) {  //   || user.getLevel() < 3
            response.sendRedirect(request.getContextPath() + "/login.jsp?msg=You dont have permission");

            return false;
        }
        return true;
    }
}
